package com.beiwei.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.beiwei.auto.mode.Job;
import com.beiwei.auto.mode.JobExample;
import com.beiwei.mapper.VJobMapper;

@Service
public class JobService {

	@Autowired
	private VJobMapper vJobMapper;

	/**
	 * 根据jobId查询Job
	 */
	public Job findJobByJobId(Integer jobId) throws Exception {
		return vJobMapper.selectByPrimaryKey(jobId);
	}

	/**
	 * 根据部门id查询出该部门下所有的岗位
	 */
	public List<Job> findJobListByDepartmentId(Integer departmentId) throws Exception {
		JobExample example = new JobExample();
		JobExample.Criteria criteria = example.createCriteria();
		criteria.andJobDepartmentIdEqualTo(departmentId);
		criteria.andDelFlagEqualTo(0);

		return vJobMapper.selectByExample(example);
	}

	/**
	 * 保存新加岗位
	 */
	public boolean addJob(Job job) throws Exception {
		if (1 == vJobMapper.insertSelective(job)) {
			return true;
		}
		return false;
	}

	/**
	 * 更新岗位
	 */
	public boolean saveJob(Job job) throws Exception {
		if (1 == vJobMapper.updateByPrimaryKeySelective(job)) {
			return true;
		}
		return false;
	}

}
